package com.cskaoyan.service.wxgoods;

import com.cskaoyan.bean.CommonData;
import com.cskaoyan.bean.po.ohter.MarketBrand;
import com.cskaoyan.bean.po.ohter.MarketBrandExample;
import com.cskaoyan.bean.vo.wxgoods.BrandListInfo;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.util.beanutils.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Ajun de BBC
 * @Date 2022/7/21 11:44
 * @Version 1.5
 */

@Service
public class WxBrandServiceImpl implements WxBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    /**
     *@Description : 制造商的页面显示
     *@Param :
     *@Return :
     */
    @Override
    public CommonData<BrandListInfo> brandList(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(null);
        List<BrandListInfo> brandListInfos = new ArrayList<>();
        for (MarketBrand marketBrand : marketBrands) {
            BrandListInfo brandListInfo = new BrandListInfo();
            BeanUtil.copyBean(marketBrand,brandListInfo);
            brandListInfos.add(brandListInfo);
        }
        PageInfo<MarketBrand> brandListInfoPageInfo = new PageInfo<>(marketBrands);
        Long total = brandListInfoPageInfo.getTotal();
        int pages = brandListInfoPageInfo.getPages();
        int newPage = brandListInfoPageInfo.getPageNum();
        return new CommonData<BrandListInfo>(total.intValue(),pages,limit,newPage,brandListInfos);
    }


    /**
     *@Description : 显示指定制造商的详细信息
     *@Param :
     *@Return :
     */
    @Override
    public MarketBrand brandDetail(Integer id) {
        MarketBrand marketBrand = marketBrandMapper.selectByPrimaryKey(id);
        return marketBrand;
    }
}
